package com.apes.crm.customerCar.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.crm.car.model.CarBase;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.party.model.Party;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CustomerCarsInsurance.CONST_TABLE_NAME,
        indexes = {@Index(name = "idx_crm_customer_car_insurance", columnList = "party_id,car_id", unique = true),
                   @Index(name = "idx_crm_insurance_party", columnList = "party_id"),
                   @Index(name = "idx_crm_insurance_car", columnList = "car_id")
        })
public class CustomerCarsInsurance extends Model {
    public static final String CONST_TABLE_NAME = "crm_customer_car_insurance"; // 客户车辆保险信息

    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "客户车辆保险信息", padding = 8)
    private String id; // id

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "party_id", referencedColumnName = "id",nullable = false)
    private Party party; //  客户信息

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "car_id",referencedColumnName = "id",nullable = false)
    private CarBase car; // 车辆id

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "strong_date")
    private Date strongDate; // 交强险投保日期

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "strong_date_end")
    private Date strongDateEnd; // 交强险投保日期止

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "strong_company_id",referencedColumnName = "id")
    private PartyRole strongCompany; // 交强险公司

    @Column(name = "strong_channel")
    private String strongChannel; // 交强险出单渠道

    @Column(name = "strong_photo")
    private String strongPhoto; // 交强险保单照片

    @Column(name = "strong_track_mark",nullable = false)
    private boolean strongTrackMark = true; // 交强险跟踪标记

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "next_strong_visit_date")
    private Date nextStrongVisitDate; //  下次交强险回访日期

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "commercial_date")
    private Date commercialDate; // 商业险投保日期

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "commercial_date_end")
    private Date commercialDateEnd; // 商业险投保日期止

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "commercial_company_id",referencedColumnName = "id")
    private PartyRole commercialCompany; // 商业险公司

    @Column(name = "commercial_channel")
    private String commercialChannel; // 商业险出单渠道

    @Column(name = "commercial_photo")
    private String commercialPhoto; // 商业险保单照片

    @Column(name = "commercial_track_mark",nullable = false)
    private boolean commercialTrackMark = true; // 商业险跟踪标记

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "next_commercial_visit_date")
    private Date nextCommercialVisitDate; //  下次商业险回访日期

    @Column(name = "car_boat_tax_amt", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double carBoatTaxAmt = 0; // 车船税金额

    @Column(name = "car_boat_tax_pay_type")
    private String carBoatTaxPayType; // 车船税缴纳类型

    @Column(name = "car_tracer")
    private String carTracer; // 车险跟踪人

}
